using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Entities;
using Utility;

namespace BUS
{
    public class tbSanphamBUS
    {
        public static void Insert(tbSanpham sp)
        {
            tbSanphamDAL spDAL = new tbSanphamDAL();
            spDAL.Insert(sp);
        }
        public static void Update(tbSanpham sp)
        {
            tbSanphamDAL spDAL = new tbSanphamDAL();
            spDAL.Update(sp);
        }
        public static void Updatettsp(tbSanpham sp)
        {
            tbSanphamDAL spDAL = new tbSanphamDAL();
            spDAL.Updatettsp(sp);
        }
        public static void Updatetlck(tbSanpham sp)
        {
            tbSanphamDAL spDAL = new tbSanphamDAL();
            spDAL.Updatetlck(sp);
        }
        public static void Updatettdn(tbSanpham sp)
        {
            tbSanphamDAL spDAL = new tbSanphamDAL();
            spDAL.Updatettdn(sp);
        }
        public static void Delete(int iD)
        {
            tbSanphamDAL spDAL = new tbSanphamDAL();
            spDAL.Delete(iD);
        }
        public static tbSanphamCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbSanphamDAL spDAL = new tbSanphamDAL();
            return spDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbSanphamCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbSanphamDAL spDAL = new tbSanphamDAL();
            return spDAL.Get(cri.Criter, 0, 0, tbSanphamColumn.Masp.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbSanpham GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbSanphamColumn.Masp.ToString(), Condition.EQUAL, iD);
            tbSanphamDAL spDAL = new tbSanphamDAL();
            tbSanphamCollection tbsanphamCollection = spDAL.Get(cri.Criter, 0, 0, tbSanphamColumn.Masp.ToString(), OrderDirection.ASC.ToString(), out total);
            if (tbsanphamCollection.Count > 0)
                return tbsanphamCollection[0];
            return null;
        }
        public static tbSanphamCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbSanphamDAL spDAL = new tbSanphamDAL();
            return spDAL.Get(cri.Criter, 1, number,
             tbSanphamColumn.Masp.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbSanphamCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbSanphamDAL spDAL = new tbSanphamDAL();
            return spDAL.Get(cri.Criter, 1, number,
               tbSanphamColumn.Masp.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
